
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>猜数字</title>
		<script>
			 //页面加载时调用函数Math.random() // 生成0-100之间的数
			 //输入猜出的数字，并提示大小
			 var n = parseInt(Math.random() * 100) + 1;
			 console.log(n)
			 function guess(){
				 //console.log(111111)
				 var text = document.getElementById("num");
				 var span = document.getElementById("result");
				 //获取文本框的值
				 var val = text.value;
				 if(val =='' || isNaN(val)){
					 span.innerHTML = "请输入数字";
				 }else{
					 //如果是数字，比较n的值
					 if(val < n){
						 span.innerHTML = "小了";
					 }else if(val > n){
						 span.innerHTML = "大了";
					 }else if(val == n){
						 span.innerHTML = "对了";
					 }else{
						 span.innerHTML = "见鬼了";
					 }
				 }
			 }
			 
		</script>
	</head>
	<body>
		<p>
			<input type="text" id="num"/>
			<input type="button" value="猜" onclick="guess()" />
		</p>
		<p>
			<span id='result'></span>
		</p>
	</body>
</html>